/*
* FaceCat图形通讯框架
* 著作权编号:2015SR229355+2020SR0266727
* 上海卷卷猫信息技术有限公司
*/

package facecat.topin.mine;

import facecat.topin.sock.*;

/*
* 服务端回调接口
*/
public class ServerSocketListener implements FCSocketListener{
    public static int m_requestID = 0;
    
    public static int getRequestID(){
        return m_requestID++;
    }
    
    public static int m_flow = 0;
    
     /*
    * 回调方法
    * @param socketID 客户端套接字ID
    * @param localSID 服务端套接字ID
    * @param str 数据
    * @param len 数据长度
    */
    public void callBack(int socketID, int localSID, byte[] str, int len){
        try{
            //System.out.println("服务端收到用户" + new Integer(socketID).toString() + "发送的消息");
            //接收客户端信息
            FCBinary br = new FCBinary();
            br.write(str, len);
            int head = br.readInt();
            int size = br.readInt();
            byte[] bytes = new byte[size];
            br.readBytes(bytes);
            br.close();
            
            int requestID = 0;
            synchronized(this){
                requestID = getRequestID();
            }
            //服务端发给客户端
            FCBinary bw = new FCBinary();
            bw.writeInt(312);
            bw.writeInt(requestID);
            bw.writeInt(300);
            byte[] bytes2 = new byte[300];
            for(int b = 0; b < bytes2.length; b++){
                bytes2[b] = (byte)11;
            }
            bw.writeBytes(bytes2);
            byte[] sendBytes = bw.getBytes();
            FCServerSockets.send(socketID, localSID, sendBytes, sendBytes.length);
            bw.close();
            synchronized(this){
                FCFile.append("C:\\Miao\\a.txt", new Integer(requestID).toString() + "\r\n");
            }
            m_flow += len;
            synchronized(this){
                FCFile.append("C:\\Miao\\c.txt", new Integer(m_flow / 1024).toString() + "KB\r\n");
            }
        }catch(Exception ex){
            int b  = 0;
        }
    }

    /*
    * 写日志
    * @param socketID 客户端套接字ID
    * @param localSID 服务端套接字ID
    * @param state 状态
    * @param len 内容
    */
    public void writeLog(int socketID, int localSID, int state, String log){
        
    }
}
